package org.qiuer;


import org.apache.commons.io.FileUtils;
import org.qiuer.ast.Program;
import org.qiuer.compile.ASTCompiler;
import org.qiuer.compile.ASTParser;
import org.qiuer.run.ASTRunner;
import org.qiuer.util.JsonUtil;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class TestApplication {
  private static final String TEST_PATH = ASTCompiler.ES_OUTPUT_PATH + "/code.json";

  public static void main(String[] args) throws IOException, Exception {

    ASTCompiler.compile();

    File file = new File(TEST_PATH);
    String jsonAst = FileUtils.readFileToString(file, "UTF-8");
    Map<String, Object> json = JsonUtil.toMap(jsonAst);

    Program program = ASTParser.parse(json);
    long start = System.currentTimeMillis();
    Object ret = ASTRunner.run(program);
    System.out.println("=======================Return==========================");
    System.out.println("耗时(ms)：" + (System.currentTimeMillis() - start));
    System.out.println(JsonUtil.toPrettyJson(ret));

  }

  static class Main{
    public static void main(String[] args) {
      long start = System.currentTimeMillis();

      List<Object> list = new ArrayList<>();
      for (int i = 0; i <= 1000000; i++){
        list.add(i);
      }

      System.out.println("耗时(ms)：" + (System.currentTimeMillis() - start));
    }
  }
}
